package com.softserve.academy.food.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;
import com.softserve.academy.food.model.mOrder;

@Entity
@Table( name = "ORDERS" )
public class eOrder  
{
	@Id
	@Column(name = "ID_ORDER")
	@GeneratedValue(generator="increment")
	@GenericGenerator(name="increment", strategy = "increment")
	private int id;
	
	@ManyToOne(fetch = FetchType.LAZY)
	private eHistoryOrders history;
	
	@ManyToOne(fetch = FetchType.LAZY)
	private eDish dish;
	
	public eOrder()
	{
	}
	
	public eOrder( mOrder order )
	{
		id = order.getId();
		dish = new eDish( order.getDish() );	
	}

	public int getId() 
	{
		return id;
	}

	public void setId(int id) 
	{
		this.id = id;
	}

	public eHistoryOrders getHistory() 
	{
		return history;
	}

	public void setHistory(eHistoryOrders history) 
	{
		this.history = history;
	}

	public eDish getDish() 
	{
		return dish;
	}

	public void setDish(eDish dish) 
	{
		this.dish = dish;
	}

	@Override
	public int hashCode() 
	{
		final int prime = 31;
		int result = 1;
		result = prime * result + ((dish == null) ? 0 : dish.hashCode());
		result = prime * result + ((history == null) ? 0 : history.hashCode());
		result = prime * result + id;
		return result;
	}

	@Override
	public boolean equals(Object obj) 
	{
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof eOrder))
			return false;
		eOrder other = (eOrder) obj;
		if (dish == null) 
		{
			if (other.dish != null)
				return false;
		} 
		else if (!dish.equals(other.dish))
			return false;
		if (history == null) 
		{
			if (other.history != null)
				return false;
		} 
		else if (!history.equals(other.history))
			return false;
		if (id != other.id)
			return false;
		return true;
	}

	@Override
	public String toString() 
	{
		return "eOrder [id=" + id + ", history=" + history + ", dish=" + dish
				+ "]";
	}

}
